/****** Object:  Stored Procedure [dbo].spChiTietPhieuNhapSelectAllBySoPN Script Date: 6/12/2012 ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[spChiTietPhieuNhapSelectAllByNgayNhapAndSoPNAndMaThuoc]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[spChiTietPhieuNhapSelectAllByNgayNhapAndSoPNAndMaThuoc]
GO

/******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:					Description:
**		--------	--------				-----------------------------------
**		20/07/2012	SongTM					Innit created
*******************************************************************************/

CREATE PROCEDURE [dbo].[spChiTietPhieuNhapSelectAllByNgayNhapAndSoPNAndMaThuoc]
(
	@SoPN nvarchar(14),
	@Mathuoc nvarchar(12),
	@tungay datetime,
	@denngay datetime
)
WITH ENCRYPTION

AS

SET NOCOUNT ON

SELECT [tbl_ChiTietPhieuNhap].SoPN,
	tbl_LuuKho.*,
	tbl_SanPham.TenHoatChat,
	tbl_SanPham.TenBietDuoc
FROM [tbl_ChiTietPhieuNhap] Inner join tbl_PhieuNhap on tbl_phieunhap.sopn=[tbl_ChiTietPhieuNhap].soPN
	INNER JOIN tbl_LuuKho ON tbl_LuuKho.MaLuuKho = [tbl_ChiTietPhieuNhap].MaLuuKho
	INNER JOIN tbl_SanPham ON tbl_SanPham.MaThuoc = tbl_LuuKho.MaThuoc
WHERE ((@SoPN is null) or @SoPN = [tbl_ChiTietPhieuNhap].[SoPN])
		AND ((@Mathuoc is null) or @Mathuoc = tbl_LuuKho.MaThuoc)
		And (( @tungay is null) or (convert(date,@tungay)<=convert(date,NgayNhapKho)))
		AND (( @denngay is null) or (convert(date,@denngay)>=convert(date,NgayNhapKho)))

GO

--GRANT EXECUTE ON [dbo].[spChiTietPhieuNhapSelectAllBySoPN] TO [sa]
--GO
